home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 51
/
Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso
/
-serious-
/
programming
/
e
/
powerd
/
source
/
examples
/
ferguson.d
< prev
next >
Wrap
Text File
|
2000-01-27
|
1KB
|
60 lines
// Ferguson.d - example of how to generate ferguson's kubics (curves) in D
MODULE 'intuition/intuition',
'utility/tagitem',
'startup/startup_ieee'
PROC main()
DEF w:PTR TO Window
IF w:=OpenWindowTags(NIL,
WA_InnerWidth,320,
WA_InnerHeight,320,
WA_IDCMP,IDCMP_CLOSEWINDOW,
WA_Flags,WFLG_DRAGBAR|WFLG_GIMMEZEROZERO|WFLG_RMBTRAP|WFLG_ACTIVATE|WFLG_CLOSEGADGET|WFLG_DEPTHGADGET,
WA_Title,'Ferguson''s Cubic',
TAG_END)
Ferguson(w.RPort,
-5.0, 0.0, // A
-10.0, 10.0, // a
5.0, 0.0, // B
-10.0,-10.0, // b
1000)
WaitPort(w.UserPort)
CloseWindow(w)
ENDIF
ENDPROC
/*
rp - window rastport
xA,yA - coordinates of point A
xa,ya - vector in point A
xB,yB - coordinates of point B
xb,yb - vector in point B
steps - number of elementar lines
*/
PROC Ferguson(rp,xA:FLOAT,yA:FLOAT,xa:FLOAT,ya:FLOAT,xB:FLOAT,yB:FLOAT,xb:FLOAT,yb:FLOAT,steps)
DEFF delta,t,x,y,f0,f1,f2,f3
DEF i
delta:=1.0/steps
SetAPen(rp,1)
x:=xA*20.0
y:=yA*-20.0
Move(rp,x+160,y+160)
FOR i:=0 TO steps
t:=delta*i
f0:=2.0*t*t*t-3.0*t*t+1.0 // Ferguson's polynoms
f1:=-2.0*t*t*t+3.0*t*t
f2:=t*t*t-2.0*t*t+t
f3:=t*t*t-t*t
x:=xA*f0+xB*f1+xa*f2+xb*f3 // parametrical representations for x and y coords
y:=yA*f0+yB*f1+ya*f2+yb*f3
x*=20.0
y*=-20.0
Draw(rp,x+160,y+160)
ENDFOR
ENDPROC
// MarK 7/8/99